using MauiBuilder.Services;

namespace MauiBuilder
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            
            // 初始化主题设置
            InitializeTheme();
        }

        protected override Window CreateWindow(IActivationState? activationState)
        {
            return new Window(new AppShell());
        }
        
        /// <summary>
        /// 初始化应用主题
        /// </summary>
        private void InitializeTheme()
        {
            try
            {
                // 应用保存的主题设置
                var themeManager = ThemeManager.Instance;
                themeManager.LoadSavedTheme();
            }
            catch (Exception ex)
            {
                // 如果主题初始化失败，使用默认主题
                if (Application.Current != null)
                {
                    Application.Current.UserAppTheme = AppTheme.Light;
                }
                System.Diagnostics.Debug.WriteLine($"初始化主题失败: {ex.Message}");
            }
        }
    }
}